#
#  Copyright 2021 The FATE Authors. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#
from collections import OrderedDict


class CheckpointManager:
    def __init__(self):
        self.checkpoints = []

    def load_checkpoints_from_disk(self):
        pass

    @property
    def checkpoints_number(self):
        return 0

    @property
    def max_checkpoints_number(self):
        return 100

    @property
    def number_indexed_checkpoints(self):
        return OrderedDict((i.step_index, i) for i in self.checkpoints)

    @property
    def name_indexed_checkpoints(self):
        return OrderedDict((i.step_name, i) for i in self.checkpoints)

    def get_checkpoint_by_index(self, step_index: int):
        return self.number_indexed_checkpoints.get(step_index)

    def get_checkpoint_by_name(self, step_name: str):
        return self.name_indexed_checkpoints.get(step_name)

    @property
    def latest_checkpoint(self):
        if self.checkpoints:
            return self.checkpoints[-1]

    @property
    def latest_step_index(self):
        if self.latest_checkpoint is not None:
            return self.latest_checkpoint.step_index

    @property
    def latest_step_name(self):
        if self.latest_checkpoint is not None:
            return self.latest_checkpoint.step_name

    def new_checkpoint(self, step_index: int, step_name: str):
        pass

    def clean(self):
        pass

    def deploy(self, new_model_version: str, model_alias: str, step_index: int = None, step_name: str = None):
        pass

    def to_dict(self, include_models: bool = False):
        pass
